package com.chat.common.exception;

import com.chat.common.result.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(CommonException.class)
    public R<?> handleCommonException(CommonException e) {
        return e.getResult();
    }

    @ExceptionHandler(Exception.class)
    public R<?> handleOtherExceptions(Exception e) {
        e.printStackTrace();
        return R.fail(e.getMessage());
    }
}
